package com.mallcai.bigdata.ladon.service.peekdata.impl;

import com.mallcai.bigdata.ladon.dpl.entity.peekdata.PeekField;
import com.mallcai.bigdata.ladon.dpl.vo.AggFunction;
import com.mallcai.bigdata.ladon.dpl.vo.DataType;
import org.apache.commons.lang3.StringUtils;

/**
 * @author feixy
 * @version 1.0
 * @date 2019-08-01 12:50
 */
public class AggDataTypeUtils {

    public static String calculateAggDataType(PeekField peekField) {
        // 没有聚合函数,直接返回字段的类型
        if(StringUtils.isEmpty(peekField.getAggExpression())){
            return peekField.getDataType();
        }
        AggFunction aggFunction = AggFunction.getByCode(peekField.getAggExpression());
        if(aggFunction == AggFunction.COUNT_DISTINCT || aggFunction == AggFunction.COUNT){
            return DataType.LONG.getCode();
        }
        return peekField.getDataType();
    }
}
